@extends('shop::layouts.master')
@section('title')
    编辑权益
@endsection
@section('tab')
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form" >
                {{csrf_field()}}
                {{ hi_form_hidden( 'id' , $info['id'] ) }}
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="x-red">*</span>服务类型</label>
                    <div class="layui-input-block" style="width: 300px;">
                        <select name="pid">
                            <option value="">请选择服务类型</option>
                            @foreach( $type_list as $key=>$item)
                                <option value="{{$key}}" @if( $key == $info['pid'] ) selected="selected" @endif >{{$item}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="x-red">*</span>收费类型</label>
                    <div class="layui-input-block" style="width: 300px;">
                        <select lay-filter="type" name="type">
                            <option value="">请选择收费类型</option>
                            <option value="1" @if( 1 == $info['type'] ) selected="selected" @endif >按次数收费</option>
                            <option value="2" @if( 2 == $info['type'] ) selected="selected" @endif >按公里数收费</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item x-city " id="type2" @if( $info['type'] == 1) hidden="" @endif>
                    @foreach( $info['extend'] as $k=>$vo )
                    <div>
                        <div class="layui-inline" style="  z-index: 2;">
                            <label class="layui-form-label">起始公里数</label>
                            <div class="layui-input-block">
                                <input type="tel" name="startkm[]" value="{{ $vo['startkm'] }}" placeholder="请输入起始公里数" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline" >
                            <label class="layui-form-label">结束公里数</label>
                            <div class="layui-input-block">
                                <input type="text" name="overkm[]" value="{{ $vo['overkm'] }}" placeholder="请输入结束公里数" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline" >
                            <label class="layui-form-label">价格</label>
                            <div class="layui-input-block">
                                <input type="text" name="pricekm[]" value="{{ $vo['price'] }}" placeholder="请输入价格" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        @if( $k == 0 )
                            <button class="layui-btn" style="margin-top: -15px;" id="add_decrease">添加</button>
                        @else
                            <button class="layui-btn" style="margin-top: -15px; " id="del_type2">删除</button>
                        @endif
                    </div>
                    @endforeach
                </div>
                <div class="layui-form-item x-city " id="type1" @if( $info['type'] == 2) hidden="" @endif >
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>价格</label>
                        <div class="layui-input-inline" style="width: 300px;">
                            <input type="text" name="price" autocomplete="off" class="layui-input" value="{{$info['price']}}" placeholder="请输入收费价格"></div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label"></label>
                    <button class="layui-btn" lay-filter="btn_edit" lay-submit="">确认</button>
                </div>
            </form>
        </div>
    </div>

@endsection


@section('tab_js')
    @include('shop::road_rescue._js')
    <script>

        layui.use(['form', 'layer', 'jquery'], function () {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;
            var is_submit = false;
            //监听提交
            form.on('submit(btn_edit)', function (data) {
                // if( is_submit ){
                //     return false;
                // }
                // is_submit = true;
                $.ajax({
                    url: js_url('shop-road-rescue-update'),
                    type: 'post',
                    data: data.field,
                    dataType: "json",
                    success: function (result) {
                        if (result.state === 0) {
                            layer.msg("编辑成功", {time: 500, icon: 6}, function () {
                                //关闭当前frame
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                        } else {
                            layer.msg(result.msg, {time: 2000, icon: 5});
                        }
                    }
                });
                return false;

            });


        });
    </script>
@endsection